﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebBanThuoc.Function;
using WebBanThuoc.Server;
using WebBanThuoc.DAO;
using WebBanThuoc.DTO;

namespace WebBanThuoc
{
    public partial class Site1 : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                getDataGeneral();
            }

            if (Request.QueryString["tenSPChon"] != null)
            {
                tenSP.Text = Request.QueryString["tenSPChon"];
            }
            if (Request.QueryString["giaChon"] != null)
            {
                dl_chongia.Items.FindByValue(Request.QueryString["giaChon"]).Selected = true;
            }

        }
      
        private void getDataGeneral()
        {
            IServerWeb sw = new ServerWeb();
            DanhMuc_DAO daoDM = new DanhMuc_DAO(sw.Connection);
            LoaiSanPham_DAO daoLSP = new LoaiSanPham_DAO(sw.Connection);
            SanPham_DAO daoSP = new SanPham_DAO(sw.Connection);
            List<SanPham> listSP_h = daoSP.getList_Paging_isNew(1, 10);//lấy sp mới cho headline
             Session.Add("listSP_h", listSP_h);
            List<DanhMuc> listDM = daoDM.getListByKey();
            List<LoaiSanPham> fulllistLSP = daoLSP.getListByKey();
            Session.Add("fulllistLSP", fulllistLSP);
            List<LoaiSanPham> listLSP = null;
            Session.Add("listDM", listDM);

            for (int i = 0; i < listDM.Count; i++)
            {
                listLSP = daoLSP.getListByKey(listDM[i].MaDanhMuc.ToString());
                string msp = daoSP.createMaSanPham();
                Session.Add(listDM[i].MaDanhMuc.ToString(), listLSP);
            }
            List<SanPham> listSPmoi = daoSP.getListByKey();
            Session.Add("listSPmoi", listSPmoi);
            if (Session["dem"] == null)
            {
                counter.dem d = new counter.dem();
                int dem = d.get_counter();
                Session.Add("dem", dem);
            }
            sw.closeConnection();
        }
    } 
}